<?php

declare(strict_types=1);

namespace app\controller;

use app\BaseController;
use app\model\Options;

class Option extends BaseController
{
    public function index()
    {
        $options = Options::getAll($this->isAdmin);
        return $this->result('获取成功', $options);
    }

    public function read($name)
    {
        $option = Options::getOption($name, $this->isAdmin);
        return $this->result('获取成功', $option);
    }

    public function update()
    {
        $params = $this->request->put();

        if (!$this->isAdmin) return $this->result('权限不足', [], 10010);
        Options::setOptions($params);
        $options = Options::getAll($this->isAdmin);
        return $this->result('更新成功', $options);
    }
}
